using System.Text.Json.Serialization;
using MQTTnet.Formatter;
using MQTTnet.Protocol;

namespace Digitalmes.Infrastructure.MQ.Mqtt;

/// <summary>
/// MQTT 客户端配置
/// </summary>
public sealed class MqttOptions
{
    /// <summary>
    /// 服务器地址
    /// </summary>
    [NotNull]
    public string? Host { get; set; }

    /// <summary>
    /// 服务器端口
    /// </summary>
    public int? Port { get; set; }

    /// <summary>
    /// 客户端 ID
    /// </summary>
    public string? ClientId { get; set; }

    /// <summary>
    /// 用户名
    /// </summary>
    public string? Username { get; set; }

    /// <summary>
    /// 密码，在 <see cref="Username"/> 有值时有效
    /// </summary>
    public string? Password { get; set; }

    /// <summary>
    /// QoS
    /// </summary>
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public MqttQualityOfServiceLevel? QoS { get; set; }

    /// <summary>
    /// MQTT 协议版本
    /// </summary>
    [JsonConverter(typeof(JsonStringEnumConverter))]
    public MqttProtocolVersion? ProtocolVersion { get; set; }

    /// <summary>
    /// 是否让 Broker 保留消息。
    /// </summary>
    public bool? Retain { get; set; }

    /// <summary>
    /// 保活间隔，单位秒。
    /// </summary>
    public int? KeepAlivePeriod { get; set; }

    /// <summary>
    /// 超时时长，单位秒。
    /// </summary>
    public int? Timeout { get; set; }
}
